package com.wc.blue_bridge_history.Java12Q.A_纯质数;

import java.io.PrintWriter;

/**
 * @Author congge
 * @Date 2024/5/20 18:15
 * @description https://www.lanqiao.cn/problems/1561/learning/
 */
public class Main {
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 20210605 + 10, idx = 0;
    static boolean[] st = new boolean[N];
    static int[] primes = new int[N / 10];


    static void ola() {
        st[0] = st[1] = true;
        for (int i = 2; i <= N - 1; i++) {
            if (!st[i]) primes[++idx] = i;
            for (int j = 1; primes[j] <= (N - 1) / i; j++) {
                st[primes[j] * i] = true;
                if (i % primes[j] == 0) break;
            }
        }
    }

    public static void main(String[] args) {
        ola();
        int res = 0;
        int n = 20210605;
        for (int i = 1; i <= idx && primes[i] <= n; i++) {
            if (check(primes[i])) res++;
        }
        out.println(res);
        out.flush();
    }

    static boolean check(int x){
        while (x > 0){
            if (st[x % 10]) return false;
            x /= 10;
        }

        return true;
    }
}